/*
 * SystemFontSet.java  0.4.0 / Oct 25, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
package com.cute4j.swing.styles;

import java.util.WeakHashMap;

import com.cute4j.swing.graphics.Font;


/**
 * System Font Set.
 *
 * @author Slobodan Vrkacevic
 * @version 0.4.0
 */
public final class SystemFontSet extends FontSet {

// Private Static Fields. ------------------------------------------------------

  private static WeakHashMap fontSetCache;

// Static Initialization. ------------------------------------------------------

  static {
    fontSetCache = new WeakHashMap();
  }

// Package-Private Fields. -----------------------------------------------------

  final String name;

// Public Constructors. --------------------------------------------------------

  /**
   * Constructs new SystemFontSet object.
   */
  public SystemFontSet() {
    this("System");
  }

// Package-Private Constructors. -----------------------------------------------

  SystemFontSet(String name) {
    if (name == null) {
      throw new IllegalArgumentException("Null name");
    }
    this.name = name;
  }

// Overridden Methods. ---------------------------------------------------------

  /**
   * {@inheritDoc}
   */
  public boolean equals(Object obj) {
    if (obj == this) {
      return true;
    }
    if ((obj != null) && (obj.getClass() == getClass())) {
      SystemFontSet fontSet = (SystemFontSet)obj;
      return name.equals(fontSet.name);
    }
    return false;
  }

  /**
   * {@inheritDoc}
   */
  public int hashCode() {
    return getFontSet().hashCode();
  }

  /**
   * {@inheritDoc}
   */
  public String getName() {
    return name;
  }

  /**
   * {@inheritDoc}
   */
  public Font getDefaultFont() {
    return getFontSet().getDefaultFont();
  }

  /**
   * {@inheritDoc}
   */
  public Font getFixedFont() {
    return getFontSet().getFixedFont();
  }

  /**
   * {@inheritDoc}
   */
  public Font getComponentFont() {
    return getFontSet().getComponentFont();
  }

  /**
   * {@inheritDoc}
   */
  public Font getButtonFont() {
    return getFontSet().getButtonFont();
  }

  /**
   * {@inheritDoc}
   */
  public Font getMenuFont() {
    return getFontSet().getMenuFont();
  }

  /**
   * {@inheritDoc}
   */
  public Font getMenuBarFont() {
    return getFontSet().getMenuBarFont();
  }

  /**
   * {@inheritDoc}
   */
  public Font getTextFont() {
    return getFontSet().getTextFont();
  }

  /**
   * {@inheritDoc}
   */
  public Font getToolTipFont() {
    return getFontSet().getToolTipFont();
  }

// Private Methods. ------------------------------------------------------------

  private CustomFontSet getFontSet() {
    synchronized (fontSetCache) {
      CustomFontSet fontSet = (CustomFontSet)fontSetCache.get(name);
      if (fontSet == null) {
        fontSet = new CustomFontSet(name);
        fontSetCache.put(name, fontSet);
      }
      return fontSet;
    }
  }

}
